package org.lucky.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.lucky_common.domain.ChartLine;
import org.lucky_common.domain.InviteParam;
import org.lucky_common.domain.LuckyShare;
import org.springframework.stereotype.Repository;

@Repository
public interface LuckyMapper extends BaseMapper<LuckyShare> {
    @Select("SELECT ls.*, ti.* FROM `lucky_share` ls JOIN t_invite ti ON ls.inviteCode = ti.invitedCode WHERE ls.inviteCode = #{inviteCode}")
    @Results(id = "LuckyShareMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "inviteCode", column = "inviteCode"),
            @Result(property = "inviteCode2", column = "inviteCode2"),
            @Result(property = "count", column = "count"),
            @Result(property = "verifyCount", column = "verifyCount"),
            @Result(property = "userId", column = "userId"),
            @Result(property = "parentId", column = "parentId"),
            @Result(property = "submitParam", column = "submitParam"),
            @Result(property = "inviteParam", column = "invitedCode", javaType = InviteParam.class,
                    one = @One(select = "selectInviteParam", fetchType = FetchType.EAGER ))
    })
    LuckyShare selectOneWithInvite(String inviteCode);

    @Select("SELECT * FROM t_invite WHERE invitedCode = #{invitedCode}")
    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "count2", column = "count2"),
            @Result(property = "effectiveCount", column = "effectiveCount"),
            @Result(property = "invitedCode", column = "invitedCode"),
            @Result(property = "parentId", column = "parentId")
    })
    InviteParam selectInviteParam(String invitedCode);
}
